package com.yneusoft.manage.controller;

import com.yneusoft.common.model.ResponseWrapper;
import com.yneusoft.manage.model.param.UserLoginParam;
import com.yneusoft.manage.service.LoginManageService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * 登录管理控制层
 */
@RestController
public class LoginManageController {

    @Resource
    private LoginManageService loginManager;

    /**
     * 登录得到图片验证码
     * @return imageCodeKey(验证码密钥),imageCode(验证码base64)
     */

    @GetMapping("/loginManage/getImageCode")
    public ResponseWrapper getImageCode(){
        return loginManager.getImageCode();
    }

    /**
     * 员工登录
     * @param param phone(手机号),password(登录密码),imageCode(验证码),imageCodeKey(验证码密钥)
     * @return token(jwt token),name(登录名称)
     */
    @PostMapping("/loginManage/login")
    public ResponseWrapper loginUser(@RequestBody @Validated UserLoginParam param){
        return loginManager.userLogin(param);
    }

    /**
     * 返回当前员工姓名
     * @return name
     */

    @GetMapping("/loginManage/getCurrentUser")
    public ResponseWrapper getLoginUser(){
        return loginManager.getCurrentUser();
    }
}
